package cn.torna.example.web.controller.product;

import cn.torna.example.common.Result;
import cn.torna.example.web.controller.product.param.ProductParam;
import cn.torna.example.web.controller.product.vo.ProductVO;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Arrays;

/**
 * 产品模块
 *
 * @author thc
 *
 */
@RestController
@RequestMapping("shop/product")
public class ProductController {

    /**
     * 新增产品
     * @apiNote |md|这是一个Markdown文本
     * - xxx
     * - yyy
     * - xxx
     * 前端调用伪代码:
     * ```
     *  axios.post('shop/product', data);
     * ```
     * @param param
     * @return
     */
    @PostMapping
    public Result<String> add(@RequestBody ProductParam param) {
        return Result.ok("11");
    }

    /**
     * 修改产品
     *
     * @param param
     * @return
     */
    @PutMapping
    public Result<ProductVO> update(@RequestBody ProductParam param) {
        return Result.ok(new ProductVO());
    }

    /**
     * 查询产品
     *
     * @param productNo 产品id|124
     * @return
     */
    @GetMapping
    public Result<ProductVO> get(@RequestParam Integer productNo, HttpServletRequest request) {
        String token = request.getHeader("token");
        System.out.println("token:" + token);
        ProductVO productVO = new ProductVO();
        productVO.setProductNo(String.valueOf(productNo));
        return Result.ok(productVO);
    }

}
